<!--
 * @Author: 杨有财
 * @Date: 2025-02-28 15:19:18
 * @LastEditTime: 2025-03-04 18:05:17
 * @LastEditors: 杨有财
 * @Description: 封装头部标题组件
-->

<template>
  <div class="header-title-container">
    <div>
      <span class="header-title"> {{ title || renderTitle }}</span>
      <t-space size="12px"><slot name="actions"></slot></t-space>
    </div>
    <div v-if="isShowDivider" class="header-divider"></div>
  </div>
</template>
<script setup lang="ts">
import { useLocale } from '@/locales/useLocale';

defineOptions({
  name: 'HeaderTitle',
});
const { title } = defineProps({
  title: {
    type: String,
    default: '',
  },
});
const isShowDivider = ref(false);
const { locale } = useLocale();
const route = useRoute();
onMounted(() => {
  // 获取当前语言
  if (useSlots().actions) {
    isShowDivider.value = true;
  }
});
const renderTitle = computed(() => {
  return route.meta.title[locale.value];
});
</script>

<style lang="less" scoped>
.header-title-container {
  > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .header-title {
    font-size: 16px;
    font-weight: bold;
  }
}

.header-divider {
  width: 100%;
  height: 1px;
  background: #e7e9f1;
  margin-top: 12px;
  margin-bottom: 4px;
}
</style>
